﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Sunny.UI;

namespace WinFormsSprayProcessSCADASystem
{
    public partial class UserCounterButton : UIUserControl
    {

        private UIStyle _style;
        private Color _defaultFillColor;
        private Color _defaultRectColor;

        public UserCounterButton()
        {
            InitializeComponent();
            this.Load += UserCounterButton_Load;
        }

        private void UserCounterButton_Load(object? sender, EventArgs e)
        {
            this.btn_Counter.Style = UIEXtension.Style;
            _style = this.btn_Counter.Style;
            UIEXtension.SetStyleManager += SetStyle;
        }

        private void SetStyle(UIStyleManager manager)
        {
            this.btn_Counter.Style = manager.Style;
            _style = manager.Style;
            _defaultFillColor = this.btn_Counter.FillColor;
            _defaultRectColor = this.btn_Counter.RectColor;
            if (contentButtonState)
            {
                this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
                this.btn_Counter.FillColor2 = this.btn_Counter.FillPressColor;
                this.btn_Counter.FillHoverColor = this.btn_Counter.FillPressColor;
                this.btn_Counter.RectColor = this.btn_Counter.RectPressColor;
                this.btn_Counter.RectHoverColor = this.btn_Counter.RectPressColor;
            }
        }

        private string buttonName = "空运行";

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("按钮名称")]
        public string ButtonName
        {
            get { return buttonName; }
            set
            {
                buttonName = value;
                this.btn_Counter.Text = buttonName;
            }
        }

        private int contentButtonSymbol = 361452;

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("按钮图标")]
        public int ContentButtonSymbol
        {
            get { return contentButtonSymbol; }
            set
            {
                contentButtonSymbol = value;
                this.btn_Counter.Symbol = contentButtonSymbol;
            }
        }

        private bool contentButtonState;

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("按钮状态：是否点击状态")]
        public bool ContentButtonState
        {
            get { return contentButtonState; }
            set
            {
                contentButtonState = value;
                Console.WriteLine($"---------------------------是否点击状态{value}");
                //已经按下
                if (contentButtonState)
                {
                    Console.WriteLine("---------------------------已经按下");
                    this.btn_Counter.FillColor = this.btn_Counter.FillPressColor;
                    this.btn_Counter.FillColor2 = this.btn_Counter.FillPressColor;
                    this.btn_Counter.FillHoverColor = this.btn_Counter.FillPressColor;
                    this.btn_Counter.RectColor = this.btn_Counter.RectPressColor;
                    this.btn_Counter.RectHoverColor = this.btn_Counter.RectPressColor;

                }
                //未按下
                else
                {
                    ////已经切换过主题
                    //if (this.btn_Counter.Style != _style)
                    //{
                    //    Console.WriteLine($"--{_style}----{this.btn_Counter.Style}---------已经切换过主题------------");
                    //    //this.btn_Counter.Style = _style;
                    //}
                    ////未切换过主题
                    //else
                    //{
                    Console.WriteLine("---------------未切换过主题------------");
                    this.btn_Counter.FillColor = _defaultFillColor;
                    this.btn_Counter.FillColor2 = _defaultFillColor;
                    this.btn_Counter.FillHoverColor = _defaultFillColor;
                    this.btn_Counter.RectColor = _defaultRectColor;
                    this.btn_Counter.RectHoverColor = _defaultRectColor;
                    //}
                }
            }
        }

        private string variableName;

        [Browsable(true)]
        [Category("自定义属性")]
        [Description("获取变量名称")]
        public string VariableName
        {
            get { return variableName; }
            set { variableName = value; }
        }


        [Browsable(true)]
        [Category("自定义方法")]
        [Description("点击触发")]
        public event EventHandler? ClickEvent;

        private void btn_Counter_Click(object sender, EventArgs e)
        {
            ContentButtonState = !ContentButtonState;
            ClickEvent?.Invoke(this, e);
        }

    }
}
